package com.hig.risk.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hig.risk.domain.RiskScoreControl;
import com.hig.risk.service.IRiskScoreControlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 风险、危险源识别评分及控制Controller
 * 
 * @author scp
 * @date 2024-09-25
 */
@RestController
@RequestMapping("/risk/control")
public class RiskScoreControlController extends BaseController
{
    @Autowired
    private IRiskScoreControlService riskScoreControlService;

    /**
     * 查询风险、危险源识别评分及控制列表
     */
    @PreAuthorize("@ss.hasPermi('risk:control:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskScoreControl riskScoreControl)
    {
        startPage();
        List<RiskScoreControl> list = riskScoreControlService.selectRiskScoreControlList(riskScoreControl);
        return getDataTable(list);
    }

    /**
     * 导出风险、危险源识别评分及控制列表
     */
    @PreAuthorize("@ss.hasPermi('risk:control:export')")
    @Log(title = "风险、危险源识别评分及控制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(RiskScoreControl riskScoreControl, HttpServletResponse response)
    {
        //查询最新的修订时间
        RiskScoreControl control = riskScoreControlService.selectNewRevisionTime(riskScoreControl);
        if (control != null && control.getRevisionTime() != null) {
            riskScoreControl.setRevisionTime(control.getRevisionTime());
        }
        List<RiskScoreControl> list = riskScoreControlService.selectRiskScoreControlList(riskScoreControl);
        ExcelUtil<RiskScoreControl> util = new ExcelUtil<RiskScoreControl>(RiskScoreControl.class);
        util.exportExcel(response,list, "风险、危险源识别评分及控制数据");
        return AjaxResult.success();
    }

    /**
     * 获取风险、危险源识别评分及控制详细信息
     */
    @PreAuthorize("@ss.hasPermi('risk:control:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(riskScoreControlService.selectRiskScoreControlById(id));
    }

    /**
     * 新增风险、危险源识别评分及控制
     */
    @PreAuthorize("@ss.hasPermi('risk:control:add')")
    @Log(title = "风险、危险源识别评分及控制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskScoreControl riskScoreControl)
    {
        return toAjax(riskScoreControlService.insertRiskScoreControl(riskScoreControl));
    }

    /**
     * 修改风险、危险源识别评分及控制
     */
    @PreAuthorize("@ss.hasPermi('risk:control:edit')")
    @Log(title = "风险、危险源识别评分及控制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskScoreControl riskScoreControl)
    {
        return toAjax(riskScoreControlService.updateRiskScoreControl(riskScoreControl));
    }

    /**
     * 删除风险、危险源识别评分及控制
     */
    @PreAuthorize("@ss.hasPermi('risk:control:remove')")
    @Log(title = "风险、危险源识别评分及控制", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskScoreControlService.deleteRiskScoreControlByIds(ids));
    }

    @GetMapping("/overtime")
    public AjaxResult overtime()
    {
        RiskScoreControl control = new RiskScoreControl();
        return riskScoreControlService.selectOvertime(control);
    }
}
